package com.zhuiyun.educations.api.coursefile.service.impl;

import com.github.pagehelper.PageHelper;
import com.zhuiyun.educations.api.coursefile.entity.CourseFile;
import com.zhuiyun.educations.api.coursefile.mapper.CourseFileMapper;
import com.zhuiyun.educations.api.coursefile.service.CourseFileService;
import com.zhuiyun.educations.common.response.CommonResult;
import com.zhuiyun.educations.util.pageUtil.MybatisPageHelper;
import com.zhuiyun.educations.util.pageUtil.PageRequest;
import com.zhuiyun.educations.util.pageUtil.PageResult;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.Date;


/**
 * @ClassName CourseFileServiceImpl
 * @Description TODO
 * @Author ys
 * @Date 2023/6/23 16:03
 **/
@Service
public class CourseFileServiceImpl implements CourseFileService {
    @Resource
    CourseFileMapper courseFileMapper;
    /**
     * @Author ys
     * @Description TODO 分页查询
     * @Date 2023/6/26 14:09
     * @Return CommonResult
     * @param
     */
    @Override
    public CommonResult getCourseFile(PageRequest pageRequest) {
        PageHelper.startPage(pageRequest);
        PageResult pageResult = MybatisPageHelper.getPageResult(courseFileMapper.getCourseFile(pageRequest));
        return CommonResult.ok(pageResult);
    }
    /**
     * @Author ys
     * @Description TODO 新增
     * @Date 2023/6/26 14:09
     * @Return CommonResult
     * @param
     */
    @Override
    public CommonResult addCourseFile(CourseFile courseFile, MultipartFile file, String projectName) {
        Date date =  new Date();
        courseFile.setCreateTime(date);
        courseFile.setUpdateTime(date);
        courseFile.setDelFlag("0");
        return CommonResult.ok(courseFileMapper.insertSelective(courseFile));
    }
    /**
     * @Author ys
     * @Description TODO 修改
     * @Date 2023/6/26 14:09
     * @Return CommonResult
     * @param
     */
    @Override
    public CommonResult updateCourseFile(CourseFile courseFile) {
        Date date =  new Date();
        courseFile.setUpdateTime(date);
        return  CommonResult.ok(courseFileMapper.updateByPrimaryKeySelective(courseFile));
    }

    /**
     * @Author ys
     * @Description TODO 章节下拉
     * @Date 2023/6/26 14:09
     * @Return CommonResult
     * @param
     */
    @Override
    public CommonResult fileSelect() {
        return  CommonResult.ok(courseFileMapper.fileSelect());
    }
    /**
     * @Author ys
     * @Description TODO 逻辑删除
     * @Date 2023/6/26 14:09
     * @Return CommonResult
     * @param
     */
    @Override
    public CommonResult deleteCourseFileById(int id) {
        return CommonResult.ok(courseFileMapper.deleteCourseFileById(id));
    }
}
